package main

import (
	"fmt"
	"net/http"
	_ "net/http/pprof"
	"runtime"
	"time"
)

var num = 1

func main1() {
	runtime.GOMAXPROCS(2)
	start := time.Now()
	ch1 := make(chan int, 10)
	defer close(ch1)
	go handCh(ch1)
	go func() {
		http.ListenAndServe(":1024", nil)
	}()
	for {
		if num > 10000 {
			break
		}
		ch1 <- num
		// go handCh(num)
		num++
	}
	end := time.Now().Sub(start)
	fmt.Printf("程序执行耗时:%v, num:%d", end, num)
}

func handCh(ch chan int) {
	for {
		time.Sleep(1 * time.Millisecond)
		if _, ok := <-ch; ok {
			// fmt.Printf("channel len is: %d, i = %d \n", len(ch), i)
		} else {
			return
		}
		// go func() {
		// 	http.Get("http://baidu.com")
		// }()
		// time.Sleep(10 * time.Millisecond)
	}
}

func handNum(num int) {
	// 什么都不做
}

// 无缓存通道：
//
